package com.lei.huawei;

import java.util.Scanner;

/**
 * @author: leiGer
 * @Date: 2022/02/23
 * @Time: 22:12
 */
//
public class HeChangDui {
    public static void main(String []args){
        Scanner s = new Scanner(System.in);
        while (s.hasNext()){
            int num = s.nextInt();
            int [] arr = new int[num];
            for(int i = 0;i<num;i++){
                arr[i] = s.nextInt();
            }
            int[]left = new int[num];
            int[]right = new int [num];
            left[0] = 1;
            right[num-1] = 1;
            for(int i = 0;i<num;i++){
                left[i] = 1;
                for(int j = 0;j<i;j++){
                    if(arr[i] > arr[j]){
                        left[i] = Math.max(left[j] + 1,left[i]);
                    }
                }
            }
            for(int i = num -1;i>=0;i--){
                right[i] = 1;
                for(int j = num -1;j>i;j--){
                    if(arr[i] > arr[j]){
                        right[i] = Math.max(right[j] + 1,right[i]);
                    }
                }
            }
            int []res = new int[num];
            for(int i = 0;i<num;i++){
                res[i] = left[i] + right[i] - 1;
            }
            int max= 1;
            for(int i = 0;i<num;i++){
                max = Math.max(max,res[i]);
            }
            System.out.println(num-max);
        }
    }
}
